<%= render 'spree/admin/shared/product_tabs', current: 'Prices' %>

<% content_for :page_actions do %>
  <li id="new_price_link">
    <%= button_link_to t(".new_price"), new_object_url, { :remote => true, :id => 'admin_new_product' } %>
  </li>
<% end if can?(:create, Spree::Product) %>

<% content_for :table_filter_title do %>
  <%= Spree.t(:search) %>
<% end %>

<% content_for :table_filter do %>
<div data-hook="admin_product_prices_index_search">
  <%= search_form_for [:admin, :product, @search] do |f| %>

  <div class="row">
    <div class="col-xs-4">
      <div class="field" data-hook="sku-select">
        <%= label_tag :q_variant_id_eq, Spree::Variant.model_name.human %>
        <%= f.select :variant_id_eq,
                    @product.variants_including_master.map { |v| [v.descriptive_name, v.id] },
                    {include_blank: true},
                    class: "select2 fullwidth" %>
      </div>
    </div>

    <div class="col-xs-2">
      <div class="field" data-hook="currency-select">
        <%= label_tag :q_currency_eq, Spree::Price.human_attribute_name(:currency) %>
        <%= f.select :currency_eq,
                    @prices.map(&:currency).uniq,
                    {include_blank: true},
                    class: "select2 fullwidth" %>
      </div>
    </div>

    <div class="col-xs-2">
      <div class="field" data-hook="country-select">
        <%= label_tag :q_country_iso_eq, Spree::Price.human_attribute_name(:country) %>
        <%= f.select :country_iso_eq,
                    @prices.map(&:country).compact.uniq.map { |c| [c.name, c.iso]},
                    {include_blank: true},
                    class: "select2 fullwidth" %>
      </div>
    </div>

    <div class="col-xs-2">
      <div class="field">
        <%= label_tag :q_amount_gt, t(".amount_greater_than") %>
        <%= f.text_field :amount_gt %>
      </div>
    </div>

    <div class="col-xs-2">
      <div class="field">
        <%= label_tag :q_amount_lt, t(".amount_less_than") %>
        <%= f.text_field :amount_lt %>
      </div>
    </div>
  </div>
  <div class="clearfix"></div>

  <div class="actions filter-actions">
    <div data-hook="admin_orders_index_search_buttons">
      <%= button Spree.t(:filter_results) %>
    </div>
  </div>

  <% end %>
</div>
<% end %>

<%= render 'table', prices: @prices %>
